﻿function logout() {
    $.ajax({
        type: "get",
        url: $("#AppUrl").html() + "/Account/Logout",
        datatype: "json",
        success: function (rdata) {
            
                        var html = "";
                        html += "<form>";
                        html += "<fieldset>";
                        html += "<legend>Đăng nhập</legend>";
                        html += "</fieldset>";
                        html += "<div class='form-group'>";
                        html += "<label for='Manufacturer'>Tài khoản</label>";
                        html += "<input class='form-control' id='txtusername' type='text' placeholder='Email hoặc tên tài khoản'/>";
                        html += "</div>";
                        html += "<div class='form-group'>";
                        html += "<label for='Manufacturer'>Mật khẩu</label>";
                        html += "<input class='form-control' id='txtpassword' type='password' placeholder='Mật khẩu'/>";
                        html += "</div>";
                        html += "<div class='checkbox'>";
                        html += "<label>";
                        html += "<input type='checkbox' id='rememberme'/> Nhớ mật khẩu ";
                        html += "</label>";
                        html += "<input type='submit' onclick='return LoginGetInfo();' class='btn btn-default' id='btndangnhap' value='Đăng nhập'/>";

                        html += "</div>";
                        html += "</form>";
                        $("#formuserinfo").html(html);
                        $("#ifhaveaccountck").removeClass("hiddenBenefit");
                   
        }
    });
    return false;
}
function Login() {
    var username = $("#txtusername").val();
    var passsword = $("#txtpassword").val();
    var remember = $("#rememberme").is(':checked');
    var serviceid = 2;
    var AppUrl = $("#AppUrl").html();
    $.ajax({
        type: "post",
        url: AppUrl + "/Account/ajLogin",
        data: { username: username, password: passsword,serviceid:serviceid },
        datatype: "json",
        success: function (rdata) {
            if (rdata.Success)
            {

            }
            else
            {
                alert(rdata.Msg);
            }
        }
    });
            
       

    return false;
}
function LoginGetInfo() {
    var username = $("#txtusername").val();
    var passsword = $("#txtpassword").val();
    var remember = $("#rememberme").is(':checked');
    var serviceid = 2;
    var AppUrl = $("#AppUrl").html();
    $.ajax({
        type: "post",
        url: AppUrl + "/Account/ajLoginGetInfo",
        data: { username: username, password: passsword, serviceid: serviceid },
        datatype: "json",
        success: function (data) {
            if (data.Success) {
                var html = "";
                html += "<table class='table'>";
                html += "<thead>";
                html += "<tr>";
                html += "<th>Tài khoản SaveMoney của bạn.</th>";
                html += "</tr>";
                html += "</thead>";
                html += "<tbody>";
                html += '<tr>';
                html += '<td>';
                html += "Tài khoản: " + data.Username;
                html += '</td>';
                html += '</tr>';
                if (data.GroupID == 1) {
                    html += "<tr><td>Họ và Tên: " + data.Fullname + "</td></tr>";
                }
                else {
                    html += "<tr><td>Tên tổ chức: " + data.Fullname + "</td></tr>";
                }
                html += "<tr><td>Loại TK: " + data.Groupname + "</td></tr>";
                html += "<tr><td>SĐT: " + data.Phone + "</td></tr>";
                html += "<tr><td>Address: " + data.Address + "</td></tr>";
                html += "<tr>";
                html += "<td>";
                html += "<a href='http://id.savemoney.vn' target='_blank'>Thay đổi thông tin tài khoản</a> | <a href='#' id='btnthoat' onclick='return logout();'>Thoát</a>";
                html += "</td>";
                html += "</tr>";
                html += "</tbody>";
                html += "</table>";
                $("#formuserinfo").html(html);
                $("#ifhaveaccountck").addClass("hiddenBenefit");
            }
            else {
                alert(data.Msg);
            }
        }
    });



    return false;
}
$(document).ready(function () {
    $.ajax({
        type: "post",
        url: "http://localhost:8739/Account/requestlogin",
        data:{serviceid:2},
        datatype: "json",
        success: function (rvdata) {
            if (rvdata.success) {
                alert(rvdata.Username);
            }
        }
    });
});